/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/17 9:30
 * @Copyright
 */
package JDBC;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/*
两个任务：
    1.测试DBUtil是否好用
    2.模糊查询怎么写
 */
public class JDBCtest11 {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try{
            //获得连接
            conn = DBUtil.getConnection();
            //获得预编译的数据库操作对象
            //错误的写法
            /*String sql="select ename from emp where ename like '_?%'";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"M");*/

            String sql="select ename from emp where ename like ?";
            ps=conn.prepareStatement(sql);
            ps.setString(1,"_o%");
            rs = ps.executeQuery();
            while (rs.next()){
                System.out.println(rs.getString("ename"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //释放资源
            DBUtil.close(conn,ps,rs);
        }
    }
}
